// components/weather-comp/weather.js
var amapFile = require('../../libs/amap-wx.130');
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    nickName: {
      type:String,
      default: ''
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    weather:'',
    temperature: '',
    province:'',
    city: '',
    reporttime: '',
    temperature_float:'',
    msg: '早上好',
    // nickName: ''
  },
  lifetimes:{
    attached(){
        this.initFn();
    }
  },
  /**
   * 组件的方法列表
   */
  methods: {

      initFn(){
        this.getWeatherFn();
        let v = new Date().getHours();
        // console.log({v,nickName})
        let msg = '';
        if(v <= 4) {
            msg = '深夜了、';
        }
        else if( v>6  && v <= 12){
          msg = '早上';
        }
        else if( v>12  && v <= 14){
          msg = '中午';
        }
        else if( v>14  && v <= 18){
          msg = '下午';
        }
        else if( v>18  && v <= 22){
          msg = '晚上';
        }
        else if( v>22  && v <= 24){
          msg = '夜间';
        }
        this.setData({
          msg,
        })
      },
      getWeatherFn(){
        var that = this;
        // 高德地图开发中台
        var myAmapFun = new amapFile.AMapWX({key:'94edf306e1d2efa1e0a92bb09401b9a1'});
        myAmapFun.getWeather({
          success: function(data){
            //成功回调
            // console.log(data)
            let {liveData: {city,province, reporttime,temperature, temperature_float ,weather}} = data;
            that.setData({
              city,province, reporttime,temperature, temperature_float ,weather
            })
          },
          fail: function(info){
            //失败回调
            console.log(info)
          }
        })
      }
  }
})
